namespace Admin2025.Domain.Entities.App;

// 基于RABC的领域实体的实现
public class AppRole : EntityBase
{
  public string RoleName { get; set; } = null!;

  // 数据权限范围：如"All"、"Department"、"Self"
  public string DataScope { get; set; } = "Self";

  public ICollection<AppPermission> Permissions { get; set; } = new List<AppPermission>();

  // 分配权限
  public void AssignPermission(AppPermission permission)
  {
    // 如果不包含，则添加权限
    if (!Permissions.Contains(permission))
    {
      Permissions.Add(permission);
    }

  }

  // 移除权限
  public void RemovePermission(AppPermission permission)
  {
    // 如果包含指定权限，则移除
    if (Permissions.Contains(permission))
    {
      Permissions.Remove(permission);
    }

  }

  public bool HasPermission(string permissionCode)
  {
    return Permissions.Any(p => p.Code == permissionCode);
  }
}